using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Phone.Shell;
using System.IO.IsolatedStorage;

namespace PaperFighter
{
    class Tutorial : GameScreen
    {
        bool isNext = false;
        bool isExit = false;
        int planeSelect;
        float transparence = 0.0f;
        float exitTransparence = 0.0f;
        Texture2D background, blank, info;
        IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

        public Tutorial(int plane)
        {
            planeSelect = plane;
            settings["showTutorial"] = "false";
        }

        public override void LoadContent()
        {
            background = ScreenManager.Game.Content.Load<Texture2D>("background_1");
            blank = ScreenManager.Game.Content.Load<Texture2D>("blank");
            info = ScreenManager.Game.Content.Load<Texture2D>("tutorial");
            
            base.LoadContent();
        }

        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;
            if (input.IsMenuCancel(null, out playerIndex))
                isExit = true;

            if (!isExit && !isNext)
            {
                if (input.TouchState.Count > 0)
                    isNext = true;
            }

            base.HandleInput(input);
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            if (!isExit && !isNext)
            {
                if (transparence < 1)
                    transparence += 0.05f;
            }

            if (isExit || isNext)
            {
                if (exitTransparence > 1)
                {
                    ExitScreen();
                    if (isExit)
                        ScreenManager.AddScreen(new Select(), null);
                    if (isNext)
                        ScreenManager.AddScreen(new Play1(planeSelect), null);
                }

                exitTransparence += 0.05f;
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }

        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            ScreenManager.SpriteBatch.Begin();
            ScreenManager.SpriteBatch.Draw(background, Vector2.Zero, Color.White);
            ScreenManager.SpriteBatch.Draw(info, Vector2.Zero, Color.White * transparence);

            if (isNext)
                ScreenManager.SpriteBatch.Draw(blank, Vector2.Zero, new Rectangle(0, 0, 480, 800), Color.White * exitTransparence);
            if (isExit)
                ScreenManager.SpriteBatch.Draw(background, Vector2.Zero, new Rectangle(0, 0, 480, 800), Color.White * exitTransparence);

            ScreenManager.SpriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
